package TrabalhoP2P;

//peer
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;

public class Peer {

    String nickName;
    InetAddress IP;

    Peer(String nickName, InetAddress IP) {
        this.IP = IP;
        this.nickName = nickName;
    }

    void setIP(InetAddress IP) {
        this.IP = IP;
    }

    InetAddress getIP() {
        return this.IP;
    }

    void setNickName(String nickName) {
        this.nickName = nickName;
    }

    String getNickName() {
        return this.nickName;
    }

    Boolean isEqual(String nickName) {
        return (this.nickName == nickName);
    }
    
    public static void main(String argv[]) throws Exception {
        String frase;
        String fraseModificada;
        
        do{
            BufferedReader doUsuario = new BufferedReader(new InputStreamReader(System.in));
            try (Socket socketCliente = new Socket("localhost", 6789)) {
                DataOutputStream paraServidor = new DataOutputStream(socketCliente.getOutputStream());
                BufferedReader doServidor = new BufferedReader(new InputStreamReader(socketCliente.getInputStream()));
                frase = doUsuario.readLine();
                paraServidor.writeBytes(frase + '\n');
                fraseModificada = doServidor.readLine();
                System.out.println(fraseModificada);
                if(fraseModificada.equals("BYE"))break;
                //System.out.println("Do Servidor: " + fraseModificada);
            }
        }while(true);
    }
    
    
}
